#include <iostream>
#include <cstdio>
#include <string>
#include <ctime>
#include <cstdlib>
#include <unistd.h>
#include <sys/timerfd.h>
#include <sys/select.h>

/*系统定时器测试*/
void  test_timer()
{
    int timerfd = timerfd_create(CLOCK_MONOTONIC,0);
    if(timerfd == -1)
    {
        std::cout<<"timerfd_create error"<<std::endl;
    }

    struct itimerspec iterval;
    iterval.it_value.tv_sec = 3;
    iterval.it_value.tv_nsec = 0;
    iterval.it_interval.tv_sec = 3;
    iterval.it_interval.tv_nsec = 0;

    timerfd_settime(timerfd,0,&iterval,NULL);

    while(1)
    {
       int64_t exp;
       int n = read(timerfd,&exp,sizeof(exp));
       if(n != sizeof(exp))
       {
           std::cout<<"read error"<<std::endl;
       }

       std::cout<<"exp: "<< exp <<std::endl;
    }
}